#include "PageStack.hpp"
#include <stdexcept>

namespace Pdf
{
	PageStack::PageStack(size_t byteCount)
		: PageRegion(byteCount)
		, index(0)
	{
	}

	PageStack::~PageStack()
	{
	}

	char * PageStack::push()
	{
		if (index != getPageCount())
			return acquirePage(index++);
		else
			throw std::logic_error("out of memory");
	}

	void PageStack::pop()
	{
		if (index != 0)
			releasePage(--index);
		else
			throw std::logic_error("pop count grater than push count");
	}

	char * PageStack::top() const
	{
		return getPage(index - 1);
	}
}